package com.neusoft.a312cxy.android18cxy.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.neusoft.a312cxy.android18cxy.R;
import com.neusoft.a312cxy.android18cxy.activity.YiwanchengdingdanActivity;
import com.neusoft.a312cxy.android18cxy.bean.Orderlist;

import java.util.List;

/**
 * Created by Young on 2017/10/31.
 */

public class weiwanchengAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context mContext;
    private List<Orderlist> mDataList1;
    private LayoutInflater mLayoutInflater;


    public weiwanchengAdapter(Context mContext, List<Orderlist> mDataList) {
        this.mContext = mContext;
        this.mDataList1 = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }

    @Override
    public  weiwanchengAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = mLayoutInflater.inflate(R.layout.cardview_yiwancheng, parent, false);
        return new weiwanchengAdapter.ViewHolder(v);


    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final Orderlist entity =  mDataList1.get(position);
        if (null == entity)
            return;
        weiwanchengAdapter.ViewHolder viewHolder = (weiwanchengAdapter.ViewHolder) holder;
        viewHolder.price.setText(entity.getPrice());
        viewHolder.name.setText(entity.getName());
        //viewHolder.type.setText(entity.getType());
        if(entity.getType().equals("1")){
            viewHolder.type.setText("活动订单");
        }
        else if(entity.getType().equals("2")){
            viewHolder.type.setText("培训订单");

        }
        else if (entity.getType().equals("3")){
            viewHolder.type.setText("课程订单");
        }
        viewHolder.orderid.setText(entity.getId());


        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(mContext,YiwanchengdingdanActivity.class);//你要跳转的界面
                //   Intent intent =new Intent(mContext, ClubInfoActivity.class);
                Bundle bundle = new Bundle();
                bundle.putString("orderid",entity.getId());
                bundle.putString("name",entity.getName());
                bundle.putString("type",entity.getType());
                bundle.putString("price",entity.getPrice());
                intent.putExtras(bundle);
                mContext.startActivity(intent);

            }


        });

    }

    @Override
    public int getItemCount() {
        return mDataList1.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
       // ImageView photo;
        TextView price, name,type,orderid;



        public ViewHolder(View itemView) {
            super(itemView);
        //    photo= (ImageView) itemView.findViewById(R.id.photo);
            price = (TextView) itemView.findViewById(R.id.price);
            name= (TextView) itemView.findViewById(R.id.name);
            type=(TextView) itemView.findViewById( R.id.type);
            orderid=(TextView) itemView.findViewById( R.id.id);





        }
    }
}
